#!/bin/bash
#!/usr/local/bin/python
#initSec=`date -d 2015-12-03 +%s`
#finiSec=`date -d 2015-12-03 +%s`
initSec=`date -d yesterday +%s`
finiSec=`date -d yesterday +%s`
echo $initSec,$finiSec
cd /home/ganji/HiveThrift
for ((i=$initSec; i<=$finiSec;i+=`expr 24 \* 3600`))
do
        dt=`date -d "@$i" +%F`
        echo $dt
        /usr/local/bin/python /home/ganji/HiveThrift/tjkf_es.py $dt > /home/ganji/HiveThrift/tjkf_update_es/tjkf_update_es_$dt.log
        while true
        do
                if [ $? -eq 0 ]
                then    break
                else    sleep 100
                fi
        done
done
#进入取数据目录
cd /home/ganji/HiveThrift/tjkf_update_es
#--查找日志中数据结果链接
grep -iH http:// tjkf_update_es_$dt.log |grep -i results > tjkf_update_es.txt && 
cat tjkf_update_es.txt | awk -F: '{link="http:"$3;pos=match($0,/\./)-1;name=substr($0,0,pos);cmd="wget "link" -O "name".txt";system(cmd)};' && 
#更新客服的ElasticSearch
cd /home/ganji/HiveThrift
for ((i=$initSec; i<=$finiSec;i+=`expr 24 \* 3600`))
do
        dt=`date -d "@$i" +%F`
        echo $dt
        /usr/local/bin/python /home/ganji/HiveThrift/tjkf_update_es.py $dt
done

